package com.lovo;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.entity.ApplyInfoEntity;
import com.project.entity.BiddEntity;
import com.project.entity.UserEntity;
import com.project.service.IPromotionService;
import com.project.service.ISupplierService;
import com.project.service.IUserOrderRefundService;
import com.project.service.IUserService;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

@SpringBootTest(classes = com.project.MainCSC.class)
public class MQT {
    @Autowired
    RabbitTemplate rabbitTemplate;

    @Autowired
    private IUserService service;

    @Autowired
    private ISupplierService supplierService;

    @Autowired
    private IPromotionService promotionService;

    @Autowired
    private IUserOrderRefundService refundService;



    @Test
    public void sendMQ(){
        BiddEntity stu=new BiddEntity();
        stu.setInfo("嘤嘤嘤嘤");
        stu.setTitle("发过来了吗？");

        //Java对象转化为JSON对象
        String jsonObject =  JSONObject.toJSONString(stu);
        rabbitTemplate.convertAndSend("topicExchangeTwo","rabbit.BiddEntity",jsonObject);
    }

    @Test
    public void user(){
        IPage ip =service.findByItem(1,0,3);
        System.out.println(ip.getRecords()+"  "+ip.getTotal()+"  "+ip.getPages());
//        System.out.println(service.findById(1));
//        service.updateStatus(4,2,"612332");
    }

    @Test
    public void supplier(){
//        IPage ip =supplierService.findByItem(1,0);
//        System.out.println(ip.getRecords()+"  "+ip.getTotal()+"  "+ip.getPages());
//        System.out.println(supplierService.findById(1));
//        supplierService.updateStatus(1,2,"561532");
    }

    @Test
    public void promotion(){
//        IPage ip =promotionService.findByItem(1,0,3);
//        System.out.println(ip.getRecords()+"  "+ip.getTotal()+"  "+ip.getPages());
//        System.out.println(promotionService.findById(1));
//        promotionService.updateStatus(1,1,"561532");
    }

    /**
     * 招标书发送
     */
    @Test
    public void tou(){
        BiddEntity biddEntity = new BiddEntity();
//        biddEntity.setBiddRef(SnowIdUtils.uniqueLongHex());
        biddEntity.setTitle("测试招标书标题");
        biddEntity.setStatus(1);
        List<ApplyInfoEntity> applyInfoEntities = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            ApplyInfoEntity applyInfoEntity = new ApplyInfoEntity();
            applyInfoEntity.setApplyNumber(i+1);
            applyInfoEntity.setProductRef("abcd123");
            applyInfoEntity.setSize("big");
            applyInfoEntity.setColor("red");
            applyInfoEntity.setProductName("iPone14");

            applyInfoEntities.add(applyInfoEntity);
        }

//        rabbitTemplate.convertAndSend("directExchangeOne","rabbit.key",jsonObject);

    }

    @Test
    public void Refund(){
//        IPage ip =promotionService.findByItem(1,0,3);
//        System.out.println(ip.getRecords()+"  "+ip.getTotal()+"  "+ip.getPages());
//        System.out.println(promotionService.findById(1));
//        promotionService.updateStatus(1,1,"561532");
//        refundService.SupplyRefund(
//                new SupplyRefundEntity(1,"blBeqNwQJL",23,LocalDateTime.now(),666,1,1,1));


    }


}
